/**
 * Copyright (c) 2021 Choice, Inc.
 * All Rights Reserved.
 * Choice Proprietary and Confidential.
 */
package cn.ruleengine.web.function.idc;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import javax.validation.Valid;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;

import cn.ruleengine.core.annotation.Executor;
import cn.ruleengine.core.annotation.Function;
import cn.ruleengine.core.annotation.Param;
import cn.ruleengine.web.store.entity.RuleEngineIdc;
import cn.ruleengine.web.store.manager.RuleEngineIdcManager;
import lombok.extern.slf4j.Slf4j;

/**
 * 发现任何一个成立的条目即返回 TRUE
 *
 * @author <a href="mailto:danliang@myweimai.com">丹良</a>
 * @date 2021/7/28
 */
@Slf4j
@Function
public class FindAnyOneIdcFunction {

    @Resource
    private RuleEngineIdcManager ruleEngineIDCManager;

    @Executor
    public Boolean executor(@Valid @Param(value = "idcCodes", required = false) Set<String> idcCodes,
                            @Valid @Param(value = "inspectionCode", required = false) String inspectionCode) {
        LambdaQueryWrapper<RuleEngineIdc> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RuleEngineIdc::getInspectionCode, inspectionCode)
               .eq(RuleEngineIdc::getStatus, 1)
               .in(RuleEngineIdc::getIcdCode, idcCodes);
        List<RuleEngineIdc> list = ruleEngineIDCManager.list(wrapper);
        return CollectionUtils.isNotEmpty(list) && list.size() > 0;
    }

}